package com.briup.product_source.web.controller;


import com.briup.product_source.bean.Basic.FenceHouse;
import com.briup.product_source.bean.Ext.FenceHouseExt;
import com.briup.product_source.service.FenceHouseService;
import com.briup.product_source.util.Result;
import com.briup.product_source.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "栏舍管理")
@RestController
@RequestMapping("/fenceHouse")
public class FenceHouseController {
    @Autowired
    private FenceHouseService fhService;

    @ApiOperation("分页多条件查询栏舍信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true),
            @ApiImplicitParam(name = "fhName",value = "栏舍名称 ",required = false)

    })
    @GetMapping("/query")
    public Result<PageInfo<FenceHouse>> findByPage(@RequestParam Integer pageNum,
                                                   @RequestParam Integer pageSize,
                                                   @RequestParam(value = "fhName",required = false) String Name){
        PageInfo<FenceHouse> pageInfo = fhService.findByPage(pageNum, pageSize, Name);
        return ResultUtil.success(pageInfo);
    }



    @ApiOperation("根据栏舍编号查询栏舍信息以及栏圈信息接口")
    @GetMapping("selectById")
    @ApiImplicitParam(name = "fhId",value = "栏舍编号",required = true)
    public Result findById(@RequestParam(value = "fhId") String id){
        FenceHouseExt ext = fhService.findById(id);
        return ResultUtil.success(ext);
    }


    @ApiOperation("新增或修改栏舍接口")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FenceHouse fenceHouse){
        fhService.saveOrUpdate(fenceHouse);
        return ResultUtil.success();
    }

    @ApiOperation("根据id删除栏舍信息接口")
    @DeleteMapping("/deleteById/{hId}")
    @ApiImplicitParam(name = "hId",value = "栏舍编号",required = true)
    public Result deleteById(@PathVariable(value = "hId") String id){
        fhService.deleteById(id);
        return ResultUtil.success();
    }

    @ApiOperation("批量删除栏舍接口")
    @DeleteMapping("/deleteByIdAll")
    public Result deleteByIdAll(@RequestBody List<String> ids){
        fhService.deleteByBatch(ids);
        return ResultUtil.success();
    }


}
